import {role_filter} from './CONSTANT'

export default ()=> {
    // 将房间名称放入memory里,并定义该文件的有效房间，如果放错房间会报错
    if (!Memory.frameRoomData) Memory.frameRoomData = {}
    for (var RoomName in Memory.frameRoomData)
    {
        var cpu1 = Game.cpu.getUsed()
        // 房间初始化
        var thisRoomName = RoomName
        const thisRoom:Room = Game.rooms[thisRoomName]
        if (!thisRoom || !thisRoom.controller.my) return
        // 房间状态判断模块
        thisRoom.identify_room_state_01(10,20)
        /* --------------------spawn名称及memory操作---------------------*/
        var spawn1Name = Memory.frameRoomData[RoomName].spawn1
        var spawn2Name = Memory.frameRoomData[RoomName].spawn2?Memory.frameRoomData[RoomName].spawn2:''
        var spawn3Name = Memory.frameRoomData[RoomName].spawn3?Memory.frameRoomData[RoomName].spawn3:''
        var spawnName:string[] = [spawn1Name,spawn2Name,spawn3Name]
        thisRoom.mount_spawnID(spawnName)
        /* ----------------------------角色挂载------------------------------- */
        if (!global.DicCreepFrameControl) global.DicCreepFrameControl = {}
        var mountRole = [
            'vindicat01',
            'upgrade01',
            'harvest01',
            'pixel'
        ]
        if (Memory.frameRoomData[RoomName].roleData.length >= 0)
        {
            for (var r of Memory.frameRoomData[RoomName].roleData)
            {
                mountRole = _.uniq([...mountRole,r])
            }
        }
        global.DicCreepFrameControl[thisRoomName] = role_filter(mountRole)
        /* 爬虫信息初步控制模块 */
        thisRoom.Role_A2()
    
        /* 房间状态执行模块 */
        if (Memory.frameRoomData[RoomName].plan == 1)
            thisRoom.RoomState01()
        else if (Memory.frameRoomData[RoomName].plan == 2)
            thisRoom.RoomState02()
        else if (Memory.frameRoomData[RoomName].plan == 3)
            thisRoom.RoomState03()
        else
            return
        /* 任系统模块 */
        thisRoom.MissionManager()

        /* 爬虫信息手动控制模块 */
        thisRoom.RoleChangeApi()
        /* 爬虫孵化模块 */
        thisRoom.RoleAdaption()
        /* ---------------------------------- 运行建筑--------------------------------------- */
        /* 建筑任务系统 */
        // var a = Game.cpu.getUsed()
        thisRoom.StructureWork()

        // var b = Game.cpu.getUsed()
        // console.log(thisRoomName,':',b-a)
        // thisRoom.towerWork_A1()
        /* -----------------------------------运行爬虫--------------------------------------- */
        // thisRoom.FrameCreepWork()
        /* -------------------------------------结束----------------------------------------- */
        var cpu2 = Game.cpu.getUsed()
        // console.log(`${RoomName} CPU:${cpu2-cpu1}`)
    }
}